package Offer2018;

/**
 * 二维数组的查找
 * Created by 雷文康 on 2018/3/3.
 */
public class Test03 {

    public static void main(String[] args) {
        int[][] array = {{1,4,6,9}, {2,5,7,10}, {3,6,8,11}};
        System.out.println(findNum(array, 12));
    }


    public static boolean findNum(int[][] array, int num) {
        if (array == null || array.length == 0 || array[0].length == 0) {
            return false;
        }
        int rows = array.length;
        int columns = array[0].length;
        int row = 0;
        int column = columns - 1;
        while (row < rows && column >= 0) {
            if (array[row][column] == num) {
                return true;
            } else if (array[row][column] < num) {
                row++;
            } else {
                column--;
            }
        }
        return false;
    }

}
